package com.jeesite.modules.rt.web;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.rt.dao.RtAskDao;
import com.jeesite.modules.rt.entity.RtXieyi;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.rt.entity.RtAsk;
import com.jeesite.modules.rt.service.RtAskService;

/**
 * 帮助中心Controller
 * @author 李寒冰
 * @version 2024-10-24
 */
@Controller
@RequestMapping(value = "${adminPath}/rt/rtAsk")
public class RtAskController extends BaseController {

	@Autowired
	private RtAskService rtAskService;
    @Autowired
    private RtAskDao rtAskDao;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public RtAsk get(String id, boolean isNewRecord) {
		return rtAskService.get(id, isNewRecord);
	}

	@RequestMapping(value = {"xieyiFrom", ""})
	public String xieyiFrom(RtXieyi rtXieyi, Model model) {
		rtXieyi = rtAskDao.getXieyiById(rtXieyi.getId());
		model.addAttribute("rtXieyi", rtXieyi);
		return "modules/rt/rtXieyiForm";
	}

	@RequestMapping(value = {"xieyiSave", ""})
	@ResponseBody
	public String xieyiSave(RtXieyi rtXieyi) {
		rtAskDao.saveXieyi(rtXieyi);
		return renderResult(Global.TRUE, text("保存成功！"));
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("rt:rtAsk:view")
	@RequestMapping(value = {"list", ""})
	public String list(RtAsk rtAsk, Model model) {
		model.addAttribute("rtAsk", rtAsk);
		return "modules/rt/rtAskList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("rt:rtAsk:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<RtAsk> listData(RtAsk rtAsk, HttpServletRequest request, HttpServletResponse response) {
		rtAsk.setPage(new Page<>(request, response));
		Page<RtAsk> page = rtAskService.findPage(rtAsk);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("rt:rtAsk:view")
	@RequestMapping(value = "form")
	public String form(RtAsk rtAsk, Model model) {
		model.addAttribute("rtAsk", rtAsk);
		return "modules/rt/rtAskForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("rt:rtAsk:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated RtAsk rtAsk) {
		rtAsk.setCreateTime(new Date());
		rtAskService.save(rtAsk);
		return renderResult(Global.TRUE, text("保存帮助中心成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("rt:rtAsk:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(RtAsk rtAsk) {
		rtAskService.delete(rtAsk);
		return renderResult(Global.TRUE, text("删除帮助中心成功！"));
	}
	
}